package com.yssoft.controller.supervise;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yssoft.controller.BaseController;
import com.yssoft.entity.core.TProductClassify;
import com.yssoft.entity.supplier.BillCountCustom;
import com.yssoft.entity.supplier.ProductCountCustom;
import com.yssoft.service.core.AreaService;
import com.yssoft.service.core.ProductClassifyService;
import com.yssoft.service.supervise.BillCountService;
import com.yssoft.service.supervise.ProductCountService;
/**
 * 
	* @ClassName: ProductCountController
	* @Description: 产品统计
	* @author ljy
	* @date 2018年6月11日
	 *
 */
@RequestMapping("/supplier/productCount")
@Controller
public class ProductCountController extends BaseController{
	private static Logger logger=Logger.getLogger(ProductCountController.class);
	@Resource
	private BillCountService billCountService;
	@Resource
	private ProductCountService productCountService;	
	@Autowired
	private ProductClassifyService productClassifyService;
	@Resource
    private AreaService areaService;
	/**
	 * @方法名称: list
	 * @功能描述: 跳转到销售统计列表页
	 * @作者: ljy
	 * @创建时间: 2018年6月10日 上午9:53:19
	 * @param model
	 * @return String
	 */
	@RequestMapping(value = "/list")
	public String list(Model model){
		List<Map<String, Object>> jsonArray = productClassifyService.queryProClaTree();
        String areaTree = areaService.queryAreaTree();
        model.addAttribute("mJson", JSONArray.toJSON(jsonArray));
        model.addAttribute("areaTree", areaTree);	
		return "supervise/product/productList";
	}
	
	@ResponseBody
	@RequestMapping(value = "productPage")
	public JSONObject productPage(@RequestParam(name = "page",defaultValue = "0") int page , @RequestParam(name = "limit",defaultValue = "10") int limit, 
			ProductCountCustom  custom  ) throws IllegalAccessException, ClassNotFoundException{
		logger.debug( "json:"+custom.getJsonParam()  );
        JSONObject jsonObject = productCountService.queryProductPage(page, limit, custom);
        return jsonObject;
    }
	/**
	 * 
	 * @param 跳到查看对话框
	 * @return
	 * @throws ClassNotFoundException 
	 * @throws IllegalAccessException 
	 */
	@RequestMapping(value = "/materialView")
	public String querymaterialByProductId(Integer  productId ,Model model) throws IllegalAccessException, ClassNotFoundException{
		Map<String, Object> map=productCountService.querymaterialByProductId(productId);
		model.addAttribute("map",map);
		return "supervise/product/productView";
	}
 
	
}
